# -*- coding: utf-8 -*-
from typing import Union
from fastapi import APIRouter
from web.config.Logger import logger
from web.tdx.sever.HistoryQuotes import HistoryQuotes

historyRouter = APIRouter()


@historyRouter.get("/")
def read_root():
    return {"Hello": "World  history"}

@historyRouter.get("/minute")
def minute(stockCode: Union[str, None] = None):

    client = HistoryQuotes()
    data = client.minute(symbol=stockCode)
    str = data.to_json(orient='records', date_format='iso', date_unit='s')
    logger.info(str)
    return {"data":data.to_dict(orient='records')}

@historyRouter.get("/daily")
def daily(stockCode: Union[str, None] = None):
    client = HistoryQuotes()
    data = client.daily(symbol=stockCode)
    str = data.to_json(orient='records', date_format='iso', date_unit='s')
    logger.info(str)

    return {"data": data.to_dict(orient='records')}
